with open('test.txt', mode='a+', encoding='utf-8', buffering=12) as f:
    while True:
        read_text = input('')
        f.write(read_text)
        # 立即刷新缓冲，将内容写入磁盘
        f.flush()
 